/*
 * Copyright (C) 2011 Project R'yleh Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.Arkham;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;

public class CharacterView extends Activity  implements OnClickListener{
	
	TextView name, level, HP, MP, eqTITLE, abTITLE;
	Character character = GameFile.party.characters[0];
	Stats stats = character.getEquippedStats();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		//removes title bar and sets the theme
        this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
        
		super.onCreate(savedInstanceState);
		setContentView(R.layout.characterview);
		
		name = (TextView) findViewById(R.id.characterName);
		name.setText(character.getName());
		level = (TextView) findViewById(R.id.characterLevel);
		level.setText("Level: " + character.getLevel());
		HP = (TextView) findViewById(R.id.characterHP);
		HP.setText("HP: " + stats.getCurrentHealth() + "\\" + stats.getMaxHealth());
		MP = (TextView) findViewById(R.id.characterMP);
		MP.setText("MP: " + stats.getCurrentMagic() + "\\" + stats.getMaxMagic());
		abTITLE = (TextView) findViewById(R.id.characterStats);
		abTITLE.setText("\nAbilities:");
		eqTITLE = (TextView) findViewById(R.id.characterEquipment);
		eqTITLE.setText("\nEquipment:");
		
	    GridView gridviewStats = (GridView) findViewById(R.id.characterStatsGrid);
	    gridviewStats.setAdapter(new CharacterAdapter(this));
	    GridView gridviewEquip = (GridView) findViewById(R.id.characterEquipmentGrid);
	    gridviewEquip.setAdapter(new EquipmentAdapter(this));
        
	}
	
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
	}
	
	public class CharacterAdapter extends BaseAdapter {
		private Context context;
		private String[] texts = {
		 "Strength:", Integer.toString(stats.getStrength()), 
		 "Attack:", Integer.toString(stats.getAttackPower()),
		 "Agility:", Integer.toString(stats.getAgility()),
		 "Hit%:", Integer.toString(stats.getHitPercentage()),
		 "Vitality:", Integer.toString(stats.getVitality()),
		 "Defense:", Integer.toString(stats.getDefense()),
		 "Magic:", Integer.toString(stats.getMagic()),
		 "Evade:", Integer.toString(stats.getEvade()),
		 "Magic Defense:", Integer.toString(stats.getMagicDefense()),
		 "Magic Evade: ", Integer.toString(stats.getMagicEvade())
		 };
		
		
		public CharacterAdapter(Context context) {
		    this.context = context;
		}

		public int getCount() {
		    return texts.length;
		}

		public Object getItem(int position) {
		    return null;
		}

		public long getItemId(int position) {
		    return 0;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
		    TextView tv;
		    if (convertView == null) {
		        tv = new TextView(context);
		        tv.setLayoutParams(new GridView.LayoutParams(85, 50));
		    }
		    else {
		        tv = (TextView) convertView;
		    }
		    tv.setText(texts[position]);
		    return tv;
		}

	}
	
	public class EquipmentAdapter extends BaseAdapter {
		private Context context;
		private String[] texts = {
		 "Right Hand:", character.whatEquipped(Constants.R_HAND).getName(), 
		 "Left Hand:", character.whatEquipped(Constants.L_HAND).getName(),
		 "Helmet:", character.whatEquipped(Constants.HEAD).getName(),
		 "Armor:", character.whatEquipped(Constants.BODY).getName(),
		 "Feet:", character.whatEquipped(Constants.FEET).getName(),
		 "Acc:", character.whatEquipped(Constants.ACC).getName(),
		 };
		
		public EquipmentAdapter(Context context) {
		    this.context = context;
		}
		
		public int getCount() {
		    return texts.length;
		}

		public Object getItem(int position) {
		    return null;
		}

		public long getItemId(int position) {
		    return 0;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
		    TextView tv;
		    if (convertView == null) {
		        tv = new TextView(context);
		        tv.setLayoutParams(new GridView.LayoutParams(85, 100));
		    }
		    else {
		        tv = (TextView) convertView;
		    }
		    tv.setText(texts[position]);
		    return tv;
		}

	}
}
	